#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/times.h>
#include <unistd.h>

int fib(int n)
{
  //base cases
  if(n<=1)
    return n;
  //recursive cases
  else
    return fib(n-1)+fib(n-2);
}

void print_tms(struct tms *buf)
{
  printf("User CPU time: %ld\n",buf->tms_utime);
  printf("System CPU time: %ld\n",buf->tms_stime);
  printf("User CPU time of dead children: %ld\n",buf->tms_cutime);
  printf("System CPU time of dead children: %ld\n",buf->tms_cstime);
}
int main(int argc, char *argv[])
{
  int n,result;
  struct tms start,end;
  clock_t s,e;
  //initialize n
  if(argc == 2){
    n = atoi(argv[1]);
  }
  else{
    puts("usage: fib n");
    return 1;
  }
  assert(n>=0);
  // system("date");
  s = times(&start);
   system("date");
  result = fib(n);
  e = times(&end);

  printf("fib(%d) is %d\n",n, result);
  printf("start real:%ld\n",s);
  print_tms(&start);
  puts("------------");
  printf("end real:%ld\n",e);
  print_tms(&end);
 
  printf("clock ticks per sec:%ld\n",sysconf(_SC_CLK_TCK));
  return 0;
}
